package invalidosgibusinessservicedependency;

import invalidosgibusinessservicedependency.InvalidOSGiBusinessServiceDependencyMatch;
import java.util.Collection;
import org.eclipse.emf.common.notify.Notifier;
import org.eclipse.viatra2.emf.incquery.runtime.api.EngineManager;
import org.eclipse.viatra2.emf.incquery.runtime.api.IMatchProcessor;
import org.eclipse.viatra2.emf.incquery.runtime.api.IMatcherFactory;
import org.eclipse.viatra2.emf.incquery.runtime.api.IncQueryEngine;
import org.eclipse.viatra2.emf.incquery.runtime.api.IncQueryMatcher;
import org.eclipse.viatra2.emf.incquery.runtime.api.impl.BaseGeneratedMatcher;
import org.eclipse.viatra2.emf.incquery.runtime.exception.IncQueryRuntimeException;
import org.eclipse.viatra2.gtasm.patternmatcher.incremental.rete.misc.DeltaMonitor;
import org.eclipse.viatra2.gtasm.patternmatcher.incremental.rete.tuple.Tuple;
import sysmodel.BusinessService;
import sysmodel.OSGiBusinessService;

/**
 * Generated pattern matcher API of the InvalidOSGiBusinessServiceDependency pattern, 
 * providing pattern-specific query methods.
 * 
 * 
 * 
 * @Constraint(message=\"$osgiService.name$ OSGi business service should not depend from $otherService.name$ business service, cause it is implemented with another technology!\", severity=\"error\", location=\"osgiService\")
 * pattern InvalidOSGiBusinessServiceDependency(osgiService : OSGiBusinessService, otherService : BusinessService) = {
 * 	find ServiceDependencyPath(osgiService, otherService);
 * 	neg find OSGiBusinessService(otherService);
 * }
 * 
 * @see InvalidOSGiBusinessServiceDependencyMatch
 * @see InvalidOSGiBusinessServiceDependencyMatcherFactory
 * @see InvalidOSGiBusinessServiceDependencyProcessor
 * 
 */
public class InvalidOSGiBusinessServiceDependencyMatcher extends BaseGeneratedMatcher<InvalidOSGiBusinessServiceDependencyMatch> implements IncQueryMatcher<InvalidOSGiBusinessServiceDependencyMatch> {
  /**
   * Initializes the pattern matcher over a given EMF model root (recommended: Resource or ResourceSet). 
   * If a pattern matcher is already constructed with the same root, only a lightweight reference is created.
   * The match set will be incrementally refreshed upon updates from the given EMF root and below.
   * <p>Note: if emfRoot is a resourceSet, the scope will include even those resources that are not part of the resourceSet but are referenced. 
   * This is mainly to support nsURI-based instance-level references to registered EPackages.
   * @param emfRoot the root of the EMF tree where the pattern matcher will operate. Recommended: Resource or ResourceSet.
   * @throws IncQueryRuntimeException if an error occurs during pattern matcher creation
   * 
   */
  public InvalidOSGiBusinessServiceDependencyMatcher(final Notifier notifier) throws IncQueryRuntimeException {
    this(EngineManager.getInstance().getIncQueryEngine(notifier));
  }
  
  /**
   * Initializes the pattern matcher within an existing EMF-IncQuery engine. 
   * If the pattern matcher is already constructed in the engine, only a lightweight reference is created.
   * The match set will be incrementally refreshed upon updates.
   * @param engine the existing EMF-IncQuery engine in which this matcher will be created.
   * @throws IncQueryRuntimeException if an error occurs during pattern matcher creation
   * 
   */
  public InvalidOSGiBusinessServiceDependencyMatcher(final IncQueryEngine engine) throws IncQueryRuntimeException {
    super(engine, FACTORY);
  }
  
  /**
   * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
   * @param pOsgiService the fixed value of pattern parameter osgiService, or null if not bound.
   * @param pOtherService the fixed value of pattern parameter otherService, or null if not bound.
   * @return matches represented as a InvalidOSGiBusinessServiceDependencyMatch object.
   * 
   */
  public Collection<InvalidOSGiBusinessServiceDependencyMatch> getAllMatches(final OSGiBusinessService pOsgiService, final BusinessService pOtherService) {
    return rawGetAllMatches(new Object[]{pOsgiService, pOtherService});
    
  }
  
  /**
   * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
   * Neither determinism nor randomness of selection is guaranteed.
   * @param pOsgiService the fixed value of pattern parameter osgiService, or null if not bound.
   * @param pOtherService the fixed value of pattern parameter otherService, or null if not bound.
   * @return a match represented as a InvalidOSGiBusinessServiceDependencyMatch object, or null if no match is found.
   * 
   */
  public InvalidOSGiBusinessServiceDependencyMatch getOneArbitraryMatch(final OSGiBusinessService pOsgiService, final BusinessService pOtherService) {
    return rawGetOneArbitraryMatch(new Object[]{pOsgiService, pOtherService});
    
  }
  
  /**
   * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
   * under any possible substitution of the unspecified parameters (if any).
   * @param pOsgiService the fixed value of pattern parameter osgiService, or null if not bound.
   * @param pOtherService the fixed value of pattern parameter otherService, or null if not bound.
   * @return true if the input is a valid (partial) match of the pattern.
   * 
   */
  public boolean hasMatch(final OSGiBusinessService pOsgiService, final BusinessService pOtherService) {
    return rawHasMatch(new Object[]{pOsgiService, pOtherService});
    
  }
  
  /**
   * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
   * @param pOsgiService the fixed value of pattern parameter osgiService, or null if not bound.
   * @param pOtherService the fixed value of pattern parameter otherService, or null if not bound.
   * @return the number of pattern matches found.
   * 
   */
  public int countMatches(final OSGiBusinessService pOsgiService, final BusinessService pOtherService) {
    return rawCountMatches(new Object[]{pOsgiService, pOtherService});
    
  }
  
  /**
   * Executes the given processor on each match of the pattern that conforms to the given fixed values of some parameters.
   * @param pOsgiService the fixed value of pattern parameter osgiService, or null if not bound.
   * @param pOtherService the fixed value of pattern parameter otherService, or null if not bound.
   * @param processor the action that will process each pattern match.
   * 
   */
  public void forEachMatch(final OSGiBusinessService pOsgiService, final BusinessService pOtherService, final IMatchProcessor<? super InvalidOSGiBusinessServiceDependencyMatch> processor) {
    rawForEachMatch(new Object[]{pOsgiService, pOtherService}, processor);
    
  }
  
  /**
   * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.  
   * Neither determinism nor randomness of selection is guaranteed.
   * @param pOsgiService the fixed value of pattern parameter osgiService, or null if not bound.
   * @param pOtherService the fixed value of pattern parameter otherService, or null if not bound.
   * @param processor the action that will process the selected match. 
   * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
   * 
   */
  public boolean forOneArbitraryMatch(final OSGiBusinessService pOsgiService, final BusinessService pOtherService, final IMatchProcessor<? super InvalidOSGiBusinessServiceDependencyMatch> processor) {
    return rawForOneArbitraryMatch(new Object[]{pOsgiService, pOtherService}, processor);
    
  }
  
  /**
   * Registers a new filtered delta monitor on this pattern matcher.
   * The DeltaMonitor can be used to track changes (delta) in the set of filtered pattern matches from now on, considering those matches only that conform to the given fixed values of some parameters. 
   * It can also be reset to track changes from a later point in time, 
   * and changes can even be acknowledged on an individual basis. 
   * See {@link DeltaMonitor} for details.
   * @param fillAtStart if true, all current matches are reported as new match events; if false, the delta monitor starts empty.
   * @param pOsgiService the fixed value of pattern parameter osgiService, or null if not bound.
   * @param pOtherService the fixed value of pattern parameter otherService, or null if not bound.
   * 	 @return the delta monitor.
   * 
   */
  public DeltaMonitor<InvalidOSGiBusinessServiceDependencyMatch> newFilteredDeltaMonitor(final boolean fillAtStart, final OSGiBusinessService pOsgiService, final BusinessService pOtherService) {
    return rawNewFilteredDeltaMonitor(fillAtStart, new Object[]{pOsgiService, pOtherService});
    
  }
  
  @Override
  public InvalidOSGiBusinessServiceDependencyMatch tupleToMatch(final Tuple t) {
    try {
    	return new InvalidOSGiBusinessServiceDependencyMatch((sysmodel.OSGiBusinessService) t.get(0), (sysmodel.BusinessService) t.get(1));	
    } catch(ClassCastException e) {System.err.println("Error when executing tupleToMatch in InvalidOSGiBusinessServiceDependencyMatcher:" + e.getMessage());
    	//throw new IncQueryRuntimeException(e.getMessage());
    	return null;
    }
    
  }
  
  @Override
  public InvalidOSGiBusinessServiceDependencyMatch arrayToMatch(final Object[] match) {
    try {
    	return new InvalidOSGiBusinessServiceDependencyMatch((sysmodel.OSGiBusinessService) match[0], (sysmodel.BusinessService) match[1]);
    } catch(ClassCastException e) {System.err.println("Error when executing arrayToMatch in InvalidOSGiBusinessServiceDependencyMatcher:" + e.getMessage());
    }
    		//throw new IncQueryRuntimeException(e.getMessage());
    		return null;
    
  }
  
  public final static IMatcherFactory<InvalidOSGiBusinessServiceDependencyMatch,InvalidOSGiBusinessServiceDependencyMatcher> FACTORY =  new InvalidOSGiBusinessServiceDependencyMatcherFactory();
}
